<?php
/**
* @version 1.0.0
* @package RSSearch! 1.0.0
* @copyright (C) 2011 www.rsjoomla.com
* @license GPL, http://www.gnu.org/licenses/gpl-2.0.html
*/
defined( '_JEXEC' ) or die( 'Restricted access' );

function isJ16(){
	$jversion = new JVersion();
	$current_version =  $jversion->getShortVersion();
	return (version_compare('1.6.0', $current_version) <= 0);
}

// Get a new installer
$plg_installer = new JInstaller();

jimport('joomla.filesystem.folder');
$error = array();
if(isJ16()){

		@$plg_installer->install($this->parent->getPath('source').DS.'plugins'.DS.'plg_rssearch_content');
		$db->setQuery("UPDATE #__extensions SET published=1 WHERE `type` = 'plugin' AND `folder`='rssearch'");
		$db->query();
	
	if(file_exists(JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'k2.php')){
		@$plg_installer->install($this->parent->getPath('source').DS.'plugins'.DS.'plg_rssearch_k2');
		$db->setQuery("UPDATE #__extensions SET published=1 WHERE `element` = 'k2' AND `folder`='rssearch'");
		$db->query();
		$error['k2'] = '';
	} else $error['k2'] = 'Not Installed - You need to install K2 Component in order to use RSSearch! for K2 plugin. You can download K2 component from <a href="http://getk2.org/" target="_blank">here</a>';
	
	if(file_exists(JPATH_SITE.DS.'components'.DS.'com_rsevents'.DS.'rsevents.php')){
		@$plg_installer->install($this->parent->getPath('source').DS.'plugins'.DS.'plg_rssearch_rsevents');
		$db->setQuery("UPDATE #__extensions SET published=1 WHERE `type` = 'plugin' AND `folder`='rssearch'");
		$db->query();
		$error['rsevents'] = '';
	}else $error['rsevents'] = 'Not Installed - You need to install RSEvents! Component in order to use RSSearch! for RSEvents! plugin. You can download RSEvents! component from <a href="http://www.rsjoomla.com/joomla-components/joomla-event-calendar.html" target="_blank">here</a>';
	
	if(file_exists(JPATH_SITE.DS.'components'.DS.'com_rsmembership'.DS.'rsmembership.php')){
		@$plg_installer->install($this->parent->getPath('source').DS.'plugins'.DS.'plg_rssearch_rsmembership');
		$db->setQuery("UPDATE #__extensions SET published=1 WHERE `element` = 'rsmembership' AND `folder`='rssearch'");
		$db->query();
		$error['rsmembership'] = '';
	}else $error['rsmembership'] = 'Not Installed - You need to install RSMembership! Component in order to use RSSearch! for RSMembership! plugin. You can download RSMembership! component from <a href="http://www.rsjoomla.com/joomla-components/joomla-membership-subscriptions.html" target="_blank">here</a>';	
	
	if(file_exists(JPATH_SITE.DS.'components'.DS.'com_kunena'.DS.'kunena.php')){
		@$plg_installer->install($this->parent->getPath('source').DS.'plugins'.DS.'plg_rssearch_kunena');
		$db->setQuery("UPDATE #__extensions SET published=1 WHERE `type` = 'plugin' AND `folder`='rssearch'");
		$db->query();
		$error['kunena'] = '';
	}else $error['kunena'] = 'Not Installed - You need to install Kunena Component in order to use RSSearch! for Kunena plugin. You can download Kunena component from <a href="http://www.kunena.org/download" target="_blank">here</a>';
	
	if(file_exists(JPATH_SITE.DS.'components'.DS.'com_rsblog'.DS.'rsblog.php')){
		@$plg_installer->install($this->parent->getPath('source').DS.'plugins'.DS.'plg_rssearch_rsblog');
		$db->setQuery("UPDATE #__extensions SET published=1 WHERE `type` = 'plugin' AND `folder`='rssearch'");
		$db->query();
		$error['rsblog'] = '';
	}else $error['rsblog'] = 'Not Installed - You need to install RSBlog! Component in order to use RSSearch! for RSBlog! plugin. You can download RSBlog! component from <a href="http://www.rsjoomla.com/joomla-components/joomla-blog.html" target="_blank">here</a>';
	
	
	
		@$plg_installer->install($this->parent->getPath('source').DS.'modules'.DS.'mod_rssearch');
		$db->setQuery("UPDATE #__modules SET published=1 WHERE `module`='mod_rssearch'");
		$db->query();
}else {
	@$plg_installer->install($this->parent->getPath('source').DS.'plugins'.DS.'plg_rssearch_content');
	$db->setQuery("UPDATE #__plugins SET published=1 WHERE `element` = 'content' AND `folder`='rssearch'");
	$db->query();

	if(file_exists(JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'k2.php')){
		@$plg_installer->install($this->parent->getPath('source').DS.'plugins'.DS.'plg_rssearch_k2');
		$db->setQuery("UPDATE #__plugins SET published=1 WHERE `element` = 'k2' AND `folder`='rssearch'");
		$db->query();
		$error['k2'] = '';
	} else $error['k2'] = 'Not Installed - You need to install K2 Component in order to use RSSearch! for K2 plugin. You can download K2 component from <a href="http://getk2.org/" target="_blank">here</a>';
	if(file_exists(JPATH_SITE.DS.'components'.DS.'com_rsevents'.DS.'rsevents.php')){
		@$plg_installer->install($this->parent->getPath('source').DS.'plugins'.DS.'plg_rssearch_rsevents');
		$db->setQuery("UPDATE #__plugins SET published=1 WHERE `element` = 'rsevents' AND `folder`='rssearch'");
		$db->query();
		$error['rsevents'] = '';
	}else $error['rsevents'] = 'Not Installed - You need to install RSEvents! Component in order to use RSSearch! for RSEvents! plugin. You can download RSEvents! component from <a href="http://www.rsjoomla.com/joomla-components/joomla-event-calendar.html" target="_blank">here</a>';
	if(file_exists(JPATH_SITE.DS.'components'.DS.'com_rsmembership'.DS.'rsmembership.php')){
		@$plg_installer->install($this->parent->getPath('source').DS.'plugins'.DS.'plg_rssearch_rsmembership');
		$db->setQuery("UPDATE #__plugins SET published=1 WHERE `element` = 'rsmembership' AND `folder`='rssearch'");
		$db->query();
		$error['rsmembership'] = '';
	}else $error['rsmembership'] = 'Not Installed - You need to install RSMembership! Component in order to use RSSearch! for RSMembership! plugin. You can download RSMembership! component from <a href="http://www.rsjoomla.com/joomla-components/joomla-membership-subscriptions.html" target="_blank">here</a>';
	
	if(file_exists(JPATH_SITE.DS.'components'.DS.'com_kunena'.DS.'kunena.php')){
		@$plg_installer->install($this->parent->getPath('source').DS.'plugins'.DS.'plg_rssearch_kunena');
		$db->setQuery("UPDATE #__plugins SET published=1 WHERE `type` = 'plugin' AND `folder`='rssearch'");
		$db->query();
		$error['kunena'] = '';
	}else $error['kunena'] = 'Not Installed - You need to install Kunena Component in order to use RSSearch! for Kunena plugin. You can download Kunena component from <a href="http://www.kunena.org/download" target="_blank">here</a>';
	
	if(file_exists(JPATH_SITE.DS.'components'.DS.'com_virtuemart'.DS.'virtuemart.php')){
		@$plg_installer->install($this->parent->getPath('source').DS.'plugins'.DS.'plg_rssearch_virtuemart');
		$db->setQuery("UPDATE #__plugins SET published=1 WHERE `type` = 'plugin' AND `folder`='rssearch'");
		$db->query();
		$error['virtuemart'] = '';
	}else $error['virtuemart'] = 'Not Installed - You need to install Virtuemart Component in order to use RSSearch! for Virtuemart plugin. You can download Virtuemart component from <a href="http://virtuemart.net/downloads" target="_blank">here</a>';
	
	if(file_exists(JPATH_SITE.DS.'components'.DS.'com_mtree'.DS.'mtree.php')){
		@$plg_installer->install($this->parent->getPath('source').DS.'plugins'.DS.'plg_rssearch_mosets');
		$db->setQuery("UPDATE #__plugins SET published=1 WHERE `type` = 'plugin' AND `folder`='rssearch'");
		$db->query();
		$error['mtree'] = '';
	}else $error['mtree'] = 'Not Installed - You need to install Mosets Tree Component in order to use RSSearch! for Mosets Tree plugin. You can download Mosets Tree component from <a href="http://www.mosets.com/tree/" target="_blank">here</a>';
	
	if(file_exists(JPATH_SITE.DS.'components'.DS.'com_sobi2'.DS.'sobi2.php')){
		@$plg_installer->install($this->parent->getPath('source').DS.'plugins'.DS.'plg_rssearch_sobi2');
		$db->setQuery("UPDATE #__plugins SET published=1 WHERE `type` = 'plugin' AND `folder`='rssearch'");
		$db->query();
		$error['sobi2'] = '';
	}else $error['sobi2'] = 'Not Installed - You need to install Sobi2 Component in order to use RSSearch! for Sobi2 plugin. You can download Sobi2 component from <a href="http://www.sigsiu.net/download/" target="_blank">here</a>';
	
	if(file_exists(JPATH_SITE.DS.'components'.DS.'com_rsblog'.DS.'rsblog.php')){
		@$plg_installer->install($this->parent->getPath('source').DS.'plugins'.DS.'plg_rssearch_rsblog');
		$db->setQuery("UPDATE #__plugins SET published=1 WHERE `type` = 'plugin' AND `folder`='rssearch'");
		$db->query();
		$error['rsblog'] = '';
	}else $error['rsblog'] = 'Not Installed - You need to install RSBlog! Component in order to use RSSearch! for RSBlog! plugin. You can download RSBlog! component from <a href="http://www.rsjoomla.com/joomla-components/joomla-blog.html" target="_blank">here</a>';
	
	@$plg_installer->install($this->parent->getPath('source').DS.'modules'.DS.'mod_rssearch');
	$db->setQuery("UPDATE #__modules SET published=1 WHERE `module`='mod_rssearch'");
	$db->query();
}

//UPDATE PROCEDURE
$db =& JFactory::getDBO();
?>
	<table class="adminlist">
		<thead>
			<tr>
				<th class="title" colspan="2"><?php echo JText::_('Extension'); ?></th>
				<th width="30%"><?php echo JText::_('Status'); ?></th>
			</tr>
		</thead>
		<tfoot>
			<tr>
				<td colspan="3"></td>
			</tr>
		</tfoot>
		<tbody>
			<tr class="row0">
				<td class="key" colspan="2"><strong><?php echo 'RSSearch! '.JText::_('Component'); ?></strong></td>
				<td><strong><?php echo JText::_('Installed'); ?></strong></td>
			</tr>
			<tr>
				<th><?php echo JText::_('Plugin');?></th>
				<th><?php echo JText::_('Group ');?></th>
				<th></th>
			</tr>
			<tr class="row1">
				<td class="key">System - RSSearch! Plugin</td>
				<td class="key">system</td>
				<td><strong><?php echo JText::_('Installed'); ?></strong></td>
			</tr>
			<tr class="row0">
				<td class="key">RSSearch! - Content</td>
				<td class="key">rssearch</td>
				<td><strong><?php echo JText::_('Installed');?></strong></td>
			</tr>
			
			<tr class="row0">
				<td class="key">RSSearch! - RSEvents!</td>
				<td class="key">rssearch</td>
				<td><strong><?php echo (isset($error['rsevents']) && $error['rsevents'] != '' ? $error['rsevents'] : JText::_('Installed'));?></strong></td>
			</tr>
			<tr class="row1">
				<td class="key">RSSearch! - RSMembership!</td>
				<td class="key">rssearch</td>
				<td><strong><?php echo (isset($error['rsmembership']) && $error['rsmembership'] != '' ? $error['rsmembership'] : JText::_('Installed'));?></strong></td>
			</tr>
			<tr class="row0">
				<td class="key">RSSearch! - K2</td>
				<td class="key">rssearch</td>
				<td><strong><?php echo (isset($error['k2']) && $error['k2'] != '' ? $error['k2'] : JText::_('Installed'));?></strong></td>
			</tr>
			<tr class="row0">
				<td class="key">RSSearch! - Kunena</td>
				<td class="key">rssearch</td>
				<td><strong><?php echo (isset($error['kunena']) && $error['kunena'] != '' ? $error['kunena'] : JText::_('Installed'));?></strong></td>
			</tr>
			<tr class="row0">
				<td class="key">RSSearch! - Virtuemart</td>
				<td class="key">rssearch</td>
				<td><strong><?php echo (isset($error['virtuemart']) && $error['virtuemart'] != '' ? $error['virtuemart'] : JText::_('Installed'));?></strong></td>
			</tr>
			<tr class="row0">
				<td class="key">RSSearch! - Mosets Tree</td>
				<td class="key">rssearch</td>
				<td><strong><?php echo (isset($error['mtree']) && $error['mtree'] != '' ? $error['mtree'] : JText::_('Installed'));?></strong></td>
			</tr>
			<tr class="row0">
				<td class="key">RSSearch! - Sobi2</td>
				<td class="key">rssearch</td>
				<td><strong><?php echo (isset($error['sobi2']) && $error['sobi2'] != '' ? $error['sobi2'] : JText::_('Installed'));?></strong></td>
			</tr>
			<tr class="row0">
				<td class="key">RSSearch! - RSBlog!</td>
				<td class="key">rssearch</td>
				<td><strong><?php echo (isset($error['rsblog']) && $error['rsblog'] != '' ? $error['rsblog'] : JText::_('Installed'));?></strong></td>
			</tr>
			<tr class="row0">
				<td colspan="2" class="key"><strong>Module RSSearch!</strong></td>
				<td><strong><?php echo JText::_('Installed'); ?></strong></td>
			</tr>
		</tbody>
	</table>
	<table>
	<tr>
		<td width="1%"><img src="components/com_rssearch/assets/rssearch-box.png" alt="RSSearch! Box" /></td>
		<td align="left">
		<div id="rssearch_message">
		<p>Thank you for choosing RSSearch!</p>
		<p>New in this version:</p>
		<ul id="rssearch_changelog">
			<li>Joomla! 1.6 Compatibility</li>
			<li>Search in Content</li>
			<li>Search in RSEvents!</li>
			<li>Search in RSMembership!</li>
			<li>Search in K2</li>
			<li>Search in Kunena</li>
			<li>Search in Virtuemart</li>
			<li>Search in Mosets Tree</li>
			<li>Search in Sobi2</li>
			<li>Search in RSBlog!</li>
		</ul>
		<a href="http://www.rsjoomla.com/customer-support/documentations/118-general-overview-of-the-component/578-changelog.html" target="_blank">Full Changelog</a>
		<ul id="rssearch_links">
			<li>
				<div class="button2-left">
					<div class="next">
						<a href="index.php?option=com_rssearch">Start using RSSearch!</a>
					</div>
				</div>
			</li>
			<li>
				<div class="button2-left">
					<div class="readmore">
						<a href="http://www.rsjoomla.com/customer-support/documentations/117-rssearch.html" target="_blank">Read the RSSearch! User Guide</a>
					</div>
				</div>
			</li>
			<li>
				<div class="button2-left">
					<div class="blank">
						<a href="http://www.rsjoomla.com/customer-support/tickets.html" target="_blank">Get Support!</a>
					</div>
				</div>
			</li>
		</ul>
		</div>
		</td>
	</tr>	
</table>
<div align="left" width="100%"><b>RSSearch! 1.0.0 Installed</b></div>
<style type="text/css">
.green { color: #009E28; }
.red { color: #B8002E; }
.greenbg { background: #B8FFC9 !important; }
.redbg { background: #FFB8C9 !important; }
#rssearch_changelog
{
	list-style-type: none;
	padding: 0;
}
#rssearch_changelog li
{
	background: url(components/com_rssearch/assets/images/ok.png) no-repeat center left;
	padding-left: 24px;
}

#rssearch_links
{
	list-style-type: none;
	padding: 0;
}
</style>